package com.wj.responese;

import com.wj.constant.ResponseInfoEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
public class ResultResponse<T> {
    private int code;
    private String message;
    private T data;

    public ResultResponse(ResponseInfoEnum responseInfoEnum, T data) {
        this(responseInfoEnum.getCode(), responseInfoEnum.getMessage(), data);
    }

    public ResultResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResultResponse<T> success() {
        return success(null);
    }

    public static <T> ResultResponse<T> success(T data) {
        return new ResultResponse<>(ResponseInfoEnum.SUCCESS, data);
    }

    public static <T> ResultResponse<T> failure(T message) {
        return new ResultResponse<>(ResponseInfoEnum.FAIL, message);
    }
}
